//$URL: http://deveth0.googlecode.com/svn/trunk/demos/jersey-springsecurity/src/main/java/de/deveth0/demos/jerseyspringsecurity/data/dao/impl/DummyUserDatabase.java $
//$Id: DummyUserDatabase.java 2 2012-10-23 18:30:23Z amuthmann@gmail.com $
/*
 * Copyright 2012 deveth0.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.deveth0.demos.jerseyspringsecurity.data.dao.impl;

import de.deveth0.demos.jerseyspringsecurity.data.dao.UserDatabase;
import de.deveth0.demos.jerseyspringsecurity.data.User;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Component;

/**
 * Dummy implementation for a userdatabase which creates users according to the given id.
 *
 * if you want an admin-user, use admin:admin, for a normal user user:user.
 *
 * @author deveth0
 */
@Component
public class DummyUserDatabase implements UserDatabase {
  
  public User getUser(String pId) {
    User user = new User();
    user.setUserId(pId);
    user.setPassword(pId);
    
    User.Role role = EnumUtils.getEnum(User.Role.class, pId.toUpperCase());
    if (role != null) {
      user.addRole(role);
      if (role == User.Role.ADMIN) {
        user.setIsVerified(true);
      }
    }
    
    return user;
  }
}
